package dw.fastfile.common.dto;

import java.util.Collections;

/**
 * @description:
 * @author: wanghao
 * @create: 2024-01-31 16:41
 **/
public class CommonResponse<T> {
    private Integer code;
    private String message;

    /**
     * 200 success
     */
    private Boolean success;

    private T data;

    public CommonResponse(Integer code, String message, Boolean success, T data) {
        this.code = code;
        this.message = message;
        this.success = success;
        this.data = data;
    }

    public CommonResponse(Integer code, String message, Boolean success) {
        this.code = code;
        this.message = message;
        this.success = success;
    }

    public static CommonResponse success() {
        return new CommonResponse(200, "响应成功", true, Collections.emptyMap());
    }

    public static <T> CommonResponse<T> success(T t) {
        return new CommonResponse(200, "响应成功", true, t);
    }

    public static CommonResponse fail(String message) {
        return new CommonResponse(400, message, false);
    }

    public static CommonResponse fail(Integer code, String message) {
        return new CommonResponse(code, message, false);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
